<template>
    <div class="">
        <el-dialog title="编辑个人" :visible.sync="dialog" width="40%" :before-close="dialogClose">
            <el-form ref="formData" :model="formData" label-width="100px">
				<el-form-item label="所属户档" prop="homeid">
				    <el-select v-model="formData.homeid" style="width: 100%;" placeholder="请选择所属户档">
				    	<el-option :label="item.header + '(' + item.sn + ')'" :value="parseInt(item.id)" v-for="(item, index) in Home"></el-option>
				    </el-select>
				</el-form-item>
				<el-form-item label="与户主关系" prop="name">
				    <el-input v-model="formData.contact" placeholder="请输入与户主关系"></el-input>
				</el-form-item>
				<el-form-item label="类型" prop="sex">
					<el-select v-model="formData.addtype" style="width: 100%;" placeholder="请选择类型">
						<el-option label="正常" :value="0" ></el-option>
						<el-option label="新生" :value="1" ></el-option>
						<el-option label="迁入新人" :value="2" ></el-option>
					</el-select>
				</el-form-item>
				<el-row>
					<el-col :span="12">
						<el-form-item label="姓名" prop="name">
						    <el-input v-model="formData.name" placeholder="请输入姓名"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="电话" prop="phone">
						    <el-input v-model="formData.phone" placeholder="请输入电话"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="12">
						<el-form-item label="身份证号" prop="idcard">
						    <el-input v-model="formData.idcard" placeholder="请输入身份证号"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="性别" prop="sex">
							<el-select v-model="formData.sex" style="width: 100%;" placeholder="请选择性别">
								<el-option :label="item" :value="item" v-for="(item, index) in Site.sex"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="12">
						<el-form-item label="身份类别" prop="cate">
							<el-select v-model="formData.cate" style="width: 100%;" placeholder="请选择身份类别">
								<el-option :label="item" :value="item" v-for="(item, index) in Site.userCate"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="文化程度" prop="culture">
							<el-select v-model="formData.culture" style="width: 100%;" placeholder="请选择文化程度">
								<el-option :label="item" :value="item" v-for="(item, index) in Site.culture"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="12">
						<el-form-item label="政治面貌" prop="politics">
							<el-select v-model="formData.politics" style="width: 100%;" placeholder="请选择政治面貌">
								<el-option :label="item" :value="item" v-for="(item, index) in Site.politics"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="宗教信仰" prop="religion">
							<el-select v-model="formData.religion" style="width: 100%;" placeholder="请选择宗教信仰">
								<el-option :label="item" :value="item" v-for="(item, index) in Site.religion"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="12">
						<el-form-item label="健康状况" prop="health">
							<el-select v-model="formData.health" style="width: 100%;" placeholder="请选择健康状况">
								<el-option :label="item" :value="item" v-for="(item, index) in Site.health"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="目前状态" prop="current">
							<el-select v-model="formData.current" style="width: 100%;" placeholder="请选择目前状态">
								<el-option :label="item" :value="item" v-for="(item, index) in Site.current"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
				</el-row>
               
            	<el-form-item>
            		<el-button @click="dialogClose">取 消</el-button>
            		<el-button type="primary" @click="formSubmit">确 定</el-button>
            	</el-form-item>
            </el-form>
        </el-dialog>
    </div>
</template>
<script>
    export default {
        data() {
			return {
				dialog: false,
				Home: [],
				Site: [],
				formData: {
					id: 0,
					
				},
				homeid:0
			}
        },
		created() {
		},
		watch: {
			dialog () {
				if(!this.dialog) {
					this.clearFormData()
					this.$emit('getData')
				} else {
					this.getHome()
					this.getSite()
				}
			}
		},
        methods: {
			getHome () {
				this.$apiPost('House/getHome').then(res => {
					if(res.code == 1) {
						this.Home = res.data
						if(this.homeid){
							this.formData.homeid = parseInt(this.homeid)
						}
					}
				})
			},
			getSite () {
				this.$apiPost('Index/getSiteFile').then(res => {
					if(res.code == 1) {
						this.Site = res.data
					}
				})
			},
			dialogClose(){
				this.$emit('dialogToggle')
			},
			clearFormData () {
				this.homeid = 0
				for(let i in this.formData){
					if(i == 'id') {
						this.formData[i] = 0
					} else {
						this.formData[i] = ''
					}
				}
			},
			// 保存编辑
			formSubmit() {
				if(!this.formData.name||this.formData.name==null){
					return this.$message.error('请输入姓名！')
				}
				if(!this.formData.idcard||this.formData.idcard==null){
					return this.$message.error('请输入身份证号！')
				}
				this.$apiPost('User/editData', this.formData).then(res => {
					if(res.code == 1) {
						this.$message(res.msg)
						this.dialogClose()
					} else {
						this.$message(res.msg)
					}
				})
			},
        }
    };
</script>
<style scoped>
	.mselect{
		width: 100%;
	}
	.mtdiv{
		margin-top: 10px;
		display: inline-block;
		width: 100%;
	}
	.mtdiv .mtdiv-v{
		float: left;
		width: 50%;
		margin-bottom: 5px;
		display: flex;
		align-items: center;
	}
	.mtdiv .mtdiv-v label{
		float: left;
		margin-right: 10px;
	}
	.mtdiv .el-input{
		float: left;
		width: 80%;
		margin: 5px 0;
	}
</style>